import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

// 固定路由（不受权限影响）
export const constantRoutes = [{
        path: '/login',
        component: () =>
            import ('@/views/login/index'),
        hidden: true
    },
    {
        path: '/',
        component: Layout,
        redirect: 'dashboards',
        children: [{
            path: 'dashboards',
            name: '首页',
            component: () =>
                import ('@/views/dashboard/index'),
            meta: { title: '首页', icon: 'dashboard' }
        }]
    },
    // 第二个子菜单
    {
        path: '/nested',
        component: Layout,
        redirect: '/nested/menu1',
        name: 'nested',
        meta: {
            title: '项目管理',
            icon: 'table'
        },
        children: [{
                path: 'menu1',
                component: () =>
                    import ('@/views/nested/menu1/index'),
                name: '项目数据',
                meta: { title: '项目数据', icon: 'el-icon-s-marketing' }
            },
            {
                path: 'menu2',
                hidden: true,
                component: () =>
                    import ('@/views/nested/menu2/index'),
                name: '项目详情',
                meta: {
                    title: '项目详情',
                    activeMenu: '/nested/menu1'
                }
            },
            {
                path: 'menu3',
                component: () =>
                    import ('@/views/nested/menu3/index'),
                name: '中标项目',
                meta: { title: '中标项目', icon: 'el-icon-s-claim' }
            },
            {
                path: 'menu4',
                component: () =>
                    import ('@/views/nested/menu4/index'),
                name: '中标项目详情',
                hidden: true,
                meta: {
                    title: '中标项目详情',
                    activeMenu: '/nested/menu3'
                }
            },
        ]
    },

    // 第三个
    {
        path: '/approves',
        component: Layout,
        redirect: '/approve/approves',
        name: 'approve',
        alwaysShow: true,
        meta: {
            title: '费用管理',
            icon: 'el-icon-s-shop'
        },
        children: [{
                path: 'approves',
                component: () =>
                    import ('@/views/approve/approves/approves'),
                name: '支出详情',
                meta: {
                    title: '支出详情',
                    icon: 'el-icon-s-claim'
                }
            },
            {
                path: 'cost',
                hidden: true,
                component: () =>
                    import ('@/views/approve/cost/index'),
                name: '费用详情',
                meta: {
                    title: '费用详情',
                    activeMenu: '/approve/approves'
                }
            },
            {
                path: 'property',
                component: () =>
                    import ('@/views/approve/property/property'),
                name: '财务详情',
                meta: { title: '财务详情', icon: 'el-icon-s-data' }
            },
            {
                path: 'propertys',
                component: () =>
                    import ('@/views/approve/propertys/propertys'),
                name: '详情',
                hidden: true,
                meta: {
                    title: '详情',
                    activeMenu: '/approve/property'
                }
            }
        ]
    },
    // 第四个子菜单
    {
        path: '/expend',
        component: Layout,
        redirect: '/expend/expends',
        name: 'expend',
        meta: {
            title: '审批管理',
            icon: 'el-icon-message-solid'
        },
        children: [{
            path: 'expends',
            component: () =>
                import ('@/views/expend/expends/expends'),
            name: '项目审批',
            meta: { title: '项目审批', icon: 'el-icon-eleme' }
        }, {
            path: 'expendes',
            component: () =>
                import ('@/views/expend/expendes/expendes'),
            name: '数据审批',
            meta: { title: '数据审批', icon: 'el-icon-share' }
        }]
    },
    // 第五个子菜单
    {
        path: '/system',
        component: Layout,
        redirect: '/system/roule',
        name: 'system',
        meta: {
            title: '系统管理',
            icon: 'el-icon-s-tools'
        },
        children: [{
                path: 'user',
                component: () =>
                    import ('@/views/system/user/user'),
                name: '用户管理',
                meta: { title: '用户', icon: 'el-icon-user-solid' }
            },
            {
                path: 'roule',
                component: () =>
                    import ('@/views/system/roule/roule'),
                name: '角色管理',
                meta: { title: '角色管理', icon: 'el-icon-s-help' }
            },
        ]
    }
]

const createRouter = () => new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})

const router = createRouter()
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher
}

export default router